# -*- coding:utf-8 -*-
# @FileName  :dhcc_per_statistics.py
# @Time      :2020/12/7 10:28
# @Author    :Zhoujirong
# @Desc      :个人统计分析管理
import parameterized
import datetime,time
from biz.flow.per_statistics import PerStatisticsRequest
from common.log import Log
from common.params_operator import Param
from biz.cases.base_case import BaseCase
from common.utils import download
class TestPerStatistics(BaseCase):
    data_file_name = 'per_statistics.yaml'
    @classmethod
    def setUpClass(cls):
       cls.cookie = BaseCase().get_token()

    @parameterized.parameterized.expand(Param.from_excel('statisticsbyuser.xls'))
    def test_statistics_by_user(self,month0,
                                        year0,
                                        month1,year1,
                                        search_EQ_userType,
                                        search_EQ_batchFlag,
                                        search_EQ_source,
                                        search_EQ_autharchiveId,
                                        search_EQ_status,
                                        search_EQ_formReport,
                                        search_EQ_queryType,
                                        search_EQ_queryFormat,day0,day1,
                                        search_GTE_updateTime_DATE,
                                        search_LTE_updateTime_DATE,
                                        check,desc):
        self._testMethodDoc = desc
        ret = PerStatisticsRequest.statistics_by_user(day0,month0,
                                        year0,day1,
                                        month1,year1,
                                        search_EQ_userType,
                                        search_EQ_batchFlag,
                                        search_EQ_source,
                                        search_EQ_autharchiveId,
                                        search_EQ_status,
                                        search_EQ_formReport,
                                        search_EQ_queryType,
                                        search_EQ_queryFormat,
                                        search_GTE_updateTime_DATE,
                                        search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)

    @parameterized.parameterized.expand(Param.from_excel('statisticsbyorg.xls'))
    def test_statistics_by_org(self,day0,month0,year0,
                                day1,month1,
                                year1,search_EQ_operOrg,
                                search_EQ_batchFlag,
                                search_EQ_source,
                                search_EQ_autharchiveId,
                                search_EQ_status,
                                search_EQ_formReport,
                                search_EQ_queryFormat,
                                search_GTE_updateTime_DATE,
                                search_LTE_updateTime_DATE,check,desc):
        self._testMethodDoc = desc
        ret = PerStatisticsRequest.statistics_by_org(day0,month0,year0,
                                day1,month1,
                                year1,search_EQ_operOrg,
                                search_EQ_batchFlag,
                                search_EQ_source,
                                search_EQ_autharchiveId,
                                search_EQ_status,
                                search_EQ_formReport,
                                search_EQ_queryFormat,
                                search_GTE_updateTime_DATE,
                                search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)

    @parameterized.parameterized.expand(Param.from_excel('statisticsbyrule.xls'))
    def test_statistics_by_rule(self,search_GTE_startDate_DATE,
                                search_GTE_alertDate_DATE,
                                search_IN_deptCode,check,desc):
        self._testMethodDoc = desc
        ret = PerStatisticsRequest.statistics_by_rule(search_GTE_startDate_DATE,
                                                search_GTE_alertDate_DATE,
                                                search_IN_deptCode,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)

    def test_exportbyuser(self):
        '''按用户统计导出'''
        day0 = datetime.date.today()
        month0 = self.file_data.get('month0')
        year0 = self.file_data.get('year0')
        day1 = datetime.date.today()
        month1 = self.file_data.get('month1')
        year1 = self.file_data.get('year1')
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = datetime.date.today()
        search_LTE_updateTime_DATE = datetime.date.today()
        ret = PerStatisticsRequest.exportbyuser(day0,
                                                month0,year0,
                                                day1,month1,
                                                year1,
                                                search_EQ_batchFlag,
                                                search_EQ_source,
                                                search_EQ_autharchiveId,
                                                search_EQ_status,
                                                search_EQ_formReport,
                                                search_EQ_queryFormat,
                                                search_GTE_updateTime_DATE,
                                                search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        size = download('个人按用户统计报表dhcc_per_statisticsDtest_exportbyuser%s.xls'%time.strftime('%Y%m%d%H%M%S',time.localtime()),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_exportbyorg(self):
        '''按机构统计导出'''
        day0 = datetime.date.today()
        day1 = datetime.date.today()
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = datetime.date.today()
        search_LTE_updateTime_DATE = datetime.date.today()
        ret = PerStatisticsRequest.exportbyorg(day0,
                                                day1,search_EQ_operOrg,
                                                search_EQ_batchFlag,
                                                search_EQ_source,
                                                search_EQ_autharchiveId,
                                                search_EQ_status,
                                                search_EQ_formReport,
                                                search_EQ_queryFormat,
                                                search_GTE_updateTime_DATE,
                                                search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        size = download('个人按机构统计报表dhcc_per_statisticsDtest_exportbyorg%s.xls' % time.strftime('%Y%m%d%H%M%S', time.localtime()), ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)


    def test_getpage_user_nodate(self):
        '''按用户统计开始和结束时间为空'''
        day0 = ''
        day1 = ''
        month0 = ''
        year0 = ''
        month1 = ''
        year1 = ''
        search_EQ_userType = self.file_data.get('search_EQ_userType')
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_queryType = self.file_data.get('search_EQ_queryType')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = ''
        search_LTE_updateTime_DATE = ''
        ret = PerStatisticsRequest.statistics_by_user(day0,month0,
                                        year0,day1,
                                        month1,year1,
                                        search_EQ_userType,
                                        search_EQ_batchFlag,
                                        search_EQ_source,
                                        search_EQ_autharchiveId,
                                        search_EQ_status,
                                        search_EQ_formReport,
                                        search_EQ_queryType,
                                        search_EQ_queryFormat,
                                        search_GTE_updateTime_DATE,
                                        search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual('00000001',ret.code)
        self.assertEqual('请选择开始时间及结束时间',ret.msg)


    def test_getpage_user_nodata(self):
        '''按用户统计数据为空'''
        tmp = '2009-12-01'
        day0 = tmp
        day1 = tmp
        month0 = ''
        year0 = ''
        month1 = ''
        year1 = ''
        search_EQ_userType = self.file_data.get('search_EQ_userType')
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_queryType = self.file_data.get('search_EQ_queryType')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = PerStatisticsRequest.statistics_by_user(day0,month0,
                                        year0,day1,
                                        month1,year1,
                                        search_EQ_userType,
                                        search_EQ_batchFlag,
                                        search_EQ_source,
                                        search_EQ_autharchiveId,
                                        search_EQ_status,
                                        search_EQ_formReport,
                                        search_EQ_queryType,
                                        search_EQ_queryFormat,
                                        search_GTE_updateTime_DATE,
                                        search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual('00000001',ret.code)
        self.assertEqual('未查询到相关数据',ret.msg)

    def test_getpage_user_month(self):
        '''按用户统计按月统计'''
        tmp = time.strftime('%Y-%m',time.localtime())
        day0 = ''
        day1 = ''
        month0 = tmp
        year0 = ''
        month1 = tmp
        year1 = ''
        search_EQ_userType = ''
        search_EQ_batchFlag = ''
        search_EQ_source = ''
        search_EQ_autharchiveId = ''
        search_EQ_status = ''
        search_EQ_formReport = '2'
        search_EQ_queryType = ''
        search_EQ_queryFormat = ''
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = PerStatisticsRequest.statistics_by_user(day0,month0,
                                        year0,day1,
                                        month1,year1,
                                        search_EQ_userType,
                                        search_EQ_batchFlag,
                                        search_EQ_source,
                                        search_EQ_autharchiveId,
                                        search_EQ_status,
                                        search_EQ_formReport,
                                        search_EQ_queryType,
                                        search_EQ_queryFormat,
                                        search_GTE_updateTime_DATE,
                                        search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual(tmp,ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_getpage_user_year(self):
        '''按用户统计按年统计'''
        tmp = time.strftime('%Y',time.localtime())
        day0 = ''
        day1 = ''
        month0 = ''
        year0 = tmp
        month1 = ''
        year1 = tmp
        search_EQ_userType = ''
        search_EQ_batchFlag = ''
        search_EQ_source = ''
        search_EQ_autharchiveId = ''
        search_EQ_status = ''
        search_EQ_formReport = '3'
        search_EQ_queryType = ''
        search_EQ_queryFormat = ''
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = PerStatisticsRequest.statistics_by_user(day0,month0,
                                        year0,day1,
                                        month1,year1,
                                        search_EQ_userType,
                                        search_EQ_batchFlag,
                                        search_EQ_source,
                                        search_EQ_autharchiveId,
                                        search_EQ_status,
                                        search_EQ_formReport,
                                        search_EQ_queryType,
                                        search_EQ_queryFormat,
                                        search_GTE_updateTime_DATE,
                                        search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual(tmp,ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_getpage_user_day(self):
        '''按用户统计按天统计'''
        tmp = time.strftime('%Y-%m-%d',time.localtime())
        day0 = tmp
        day1 = tmp
        month0 = ''
        year0 = ''
        month1 = ''
        year1 = ''
        search_EQ_userType = ''
        search_EQ_batchFlag = ''
        search_EQ_source = ''
        search_EQ_autharchiveId = ''
        search_EQ_status = ''
        search_EQ_formReport = ''
        search_EQ_queryType = ''
        search_EQ_queryFormat = ''
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = PerStatisticsRequest.statistics_by_user(day0,month0,
                                        year0,day1,
                                        month1,year1,
                                        search_EQ_userType,
                                        search_EQ_batchFlag,
                                        search_EQ_source,
                                        search_EQ_autharchiveId,
                                        search_EQ_status,
                                        search_EQ_formReport,
                                        search_EQ_queryType,
                                        search_EQ_queryFormat,
                                        search_GTE_updateTime_DATE,
                                        search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual(tmp,ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    #按机构查询
    def test_exportbyorg_nodate(self):
        '''按机构统计起始结束时间为空'''
        day0 = ''
        day1 = ''
        month0 = ''
        year0 = ''
        month1 = ''
        year1 = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = ''
        search_LTE_updateTime_DATE = ''
        ret = PerStatisticsRequest.statistics_by_org(day0,
                                                    month0,year0,
                                                    day1,month1,
                                                    year1,search_EQ_operOrg,
                                                    search_EQ_batchFlag,
                                                    search_EQ_source,
                                                    search_EQ_autharchiveId,
                                                    search_EQ_status,
                                                    search_EQ_formReport,
                                                    search_EQ_queryFormat,
                                                    search_GTE_updateTime_DATE,
                                                    search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual('00000001',ret.code)
        self.assertEqual('请选择开始时间及结束时间',ret.msg)

    def test_exportbyorg_nodata(self):
        '''按机构统计无数据'''
        tmp = '2009-01-02'
        day0 = tmp
        day1 = tmp
        month0 = ''
        year0 = ''
        month1 = ''
        year1 = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = PerStatisticsRequest.statistics_by_org(day0,
                                                     month0, year0,
                                                     day1, month1,
                                                     year1, search_EQ_operOrg,
                                                     search_EQ_batchFlag,
                                                     search_EQ_source,
                                                     search_EQ_autharchiveId,
                                                     search_EQ_status,
                                                     search_EQ_formReport,
                                                     search_EQ_queryFormat,
                                                     search_GTE_updateTime_DATE,
                                                     search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual('00000001', ret.code)
        self.assertEqual('未查询到相关数据', ret.msg)

    def test_exportbyorg_day(self):
        '''按机构统计--天'''
        tmp = datetime.date.today()
        day0 = tmp
        day1 = tmp
        month0 = ''
        year0 = ''
        month1 = ''
        year1 = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = PerStatisticsRequest.statistics_by_org(day0,
                                                     month0, year0,
                                                     day1, month1,
                                                     year1, search_EQ_operOrg,
                                                     search_EQ_batchFlag,
                                                     search_EQ_source,
                                                     search_EQ_autharchiveId,
                                                     search_EQ_status,
                                                     search_EQ_formReport,
                                                     search_EQ_queryFormat,
                                                     search_GTE_updateTime_DATE,
                                                     search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual(str(tmp), ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_exportbyorg_month(self):
        '''按机构统计--月'''
        tmp = time.strftime('%Y-%m',time.localtime())
        day0 = ''
        day1 = ''
        month0 = tmp
        year0 = ''
        month1 = tmp
        year1 = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = '2'
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = PerStatisticsRequest.statistics_by_org(day0,
                                                     month0, year0,
                                                     day1, month1,
                                                     year1, search_EQ_operOrg,
                                                     search_EQ_batchFlag,
                                                     search_EQ_source,
                                                     search_EQ_autharchiveId,
                                                     search_EQ_status,
                                                     search_EQ_formReport,
                                                     search_EQ_queryFormat,
                                                     search_GTE_updateTime_DATE,
                                                     search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual(str(tmp), ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_exportbyorg_year(self):
        '''按机构统计--年'''
        tmp = time.strftime('%Y',time.localtime())
        day0 = ''
        day1 = ''
        month0 = ''
        year0 = tmp
        month1 = ''
        year1 = tmp
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = '3'
        search_EQ_operOrg = self.file_data.get('search_EQ_operOrg')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = PerStatisticsRequest.statistics_by_org(day0,
                                                     month0, year0,
                                                     day1, month1,
                                                     year1, search_EQ_operOrg,
                                                     search_EQ_batchFlag,
                                                     search_EQ_source,
                                                     search_EQ_autharchiveId,
                                                     search_EQ_status,
                                                     search_EQ_formReport,
                                                     search_EQ_queryFormat,
                                                     search_GTE_updateTime_DATE,
                                                     search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual(str(tmp), ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    #违规分析统计
    def test_statistics_by_rule_nodate(self):
        '''违规分析统计无起始结束日期'''
        search_GTE_startDate_DATE = ''
        search_GTE_alertDate_DATE = ''
        search_IN_deptCode = ''
        ret = PerStatisticsRequest.statistics_by_rule(search_GTE_startDate_DATE,
                                                search_GTE_alertDate_DATE,
                                                search_IN_deptCode,self.cookie)
        Log.info(ret)
        self.assertEqual('00000001',ret.code)
        self.assertEqual('请选择开始时间及结束时间',ret.msg)

    def test_statistics_by_rule_nodata(self):
        '''违规分析统计空数据'''
        tmp = '2007-12-12'
        search_GTE_startDate_DATE = tmp
        search_GTE_alertDate_DATE = tmp
        search_IN_deptCode = ''
        ret = PerStatisticsRequest.statistics_by_rule(search_GTE_startDate_DATE,
                                                search_GTE_alertDate_DATE,
                                                search_IN_deptCode,self.cookie)
        Log.info(ret)
        self.assertEqual('00000001', ret.code)
        self.assertEqual('您输入的查询条件没有查询到结果，请确认核对', ret.msg)


if __name__ == "__main__":
    pass